package com.hnu.store.service.impl;

import com.hnu.store.entity.Inform;
import com.hnu.store.mapper.InformMapper;
import com.hnu.store.service.IInformService;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class InformServiceImpl implements IInformService {

    @Autowired
    private InformMapper informMapper;

    @Override
    public List<Inform> getMessageListByName(String userName, String otherName){
        List<Inform> informList=informMapper.getMessageList(userName,otherName);
        return informList;
    }

    public Set<String> getSessionListByName(String userName){
        List<Inform> informList=informMapper.getSessionList(userName);
        Set<String> sessionSet=new HashSet<String>();
        for (Inform it : informList){
            sessionSet.add(it.getSendName());
            sessionSet.add(it.getReceiveName());
        }
        sessionSet.remove(userName);
        return sessionSet;
    }

    @Override
    public Inform addMessage(String sendName, String receiveName, String content){
        informMapper.insertMessage(sendName,receiveName,content);
        Inform inform=new Inform();
        inform.setContent(content);
        inform.setSendName(sendName);
        inform.setReceiveName(receiveName);
        return inform;
    }
}
